package js.dwim.domain;

import java.io.Serializable;
import java.util.Date;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.xmpp.JID;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable( identityType = IdentityType.APPLICATION, detachable = "true" )
public class CommSession
        implements Serializable
{
    private static final long serialVersionUID = 1L;

    @PrimaryKey
    @Persistent( valueStrategy = IdGeneratorStrategy.IDENTITY )
    private Key key;

    @Persistent
    private String jid;

    @Persistent( defaultFetchGroup = "true", dependent = "true" )
    private Player player;

    @Persistent
    private Date startDate;

    @Persistent
    private Date lastActivityDate;
    
    @Persistent
    private Boolean active;

    public CommSession( JID jid, Player player )
    {
        this.jid    = jid.getId();
        this.player = player;
        this.active	= false;

        this.startDate          = new Date();
        this.lastActivityDate   = new Date();
    }

    public Key getKey()
    {
        return key;
    }

    public JID getJid()
    {
        return new JID( jid );
    }

    public Player getPlayer()
    {
        return player;
    }

    public Date getStartDate()
    {
        return startDate;
    }

    public void setLastActivityDate( Date lastActivityDate )
    {
        this.lastActivityDate = lastActivityDate;
    }

    public Date getLastActivityDate()
    {
        return lastActivityDate;
    }
    
    public void setActive( boolean active )
    {
        this.active = active;
    }

    public boolean isActive()
    {
        return this.active.booleanValue();
    }
}
